package servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.Usuario;
import facade.RestauranteFacade;

/**
 * Servlet implementation class LoginServlets
 */
@WebServlet("/loginServlet")
public class LoginServlets extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlets() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
				String login = request.getParameter("login"); 
				String senha =  request.getParameter("senha");
				
				if(login == null || login.equals("") || senha == null || senha.equals("")){
					response.sendRedirect("login.html");
					return;
				}
				
				Usuario usuario = RestauranteFacade.autenticar(login, senha);
				
				
				
				if(usuario == null){
					response.sendRedirect("login.html");
					return;
				}
				
				request.getSession().setAttribute("usuario",usuario);
				
				response.sendRedirect("novaCategoria");
				
				
				
				
			}

		

	}


